package org.mybatis.jpetstore.test.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
	private ServerSocket ss;
	private Socket socket;
	private BufferedReader in;
	private PrintWriter out;
	
	public Server() throws IOException{
		try{
			ss = new ServerSocket(10008);
			while(true){
				socket = ss.accept();
				//InputStreamReader 把字节输入流，转换成字符输入流，第二个参数是编码
				//BufferedReader 缓存字符输入流
				in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				out = new PrintWriter(socket.getOutputStream(),true);
				String line = in.readLine();
				out.println("you input is :"+line);
				in.close();
				out.close();
				socket.close();
			}
			
		}catch(IOException e){
			e.printStackTrace();
		}
		finally{
			ss.close();
		}
	}
	public static void main(String[] args) throws IOException {
		new Server();
	}
}
